function getParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "": decodeURIComponent(results[1]);
}

var animsIt = [
    'bounce', 'flash', 'pulse', 'rubberBand', 'shake', 'swing', 'tada', 'wobble', 'jello',
    'fadeInDown',
    'fadeOutUp',
];

function toAnimIt(selector, anim, callback) {
    $(selector)
        .removeClass(animsIt.join(' '))
        .addClass(anim + ' animated')
        .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
            function(){
                $(this).removeClass(anim + ' animated')
                if (callback) {
                    callback();
                }
            }
        );
}

// in out
var animsInOut = [
    'fadeIn', 'fadeOut'
];

function isVisible(selector) {
    return $(selector).is(':visible');
}

function toAnimHidden(selector, anim, callback) {
    if (!isVisible(selector)) {
        callback();
        return;
    }
    $(selector)
        .removeClass(animsInOut.concat(['animated']).join(' '))
        .addClass(anim + ' animated')
        .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
            function(){
                $(this).hide();
                callback();
            }
        );
}

function toAnimVisible(selector, anim, callback) {
    if (isVisible(selector)) {
        callback();
        return;
    }
    $(selector)
        .removeClass(animsInOut.concat(['animated']).join(' '))
        .show()
        .addClass(anim + ' animated')
        .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend',
            function(){
                callback();
            }
        );
}

function showLocationPath(list) {
    var path = $('#location-tag').empty();
    list.forEach(function(m, i) {
        path.append(
            $('<li/>')
                .append(
                    $('<a href="#"/>')
                        .attr('data-href', m.href)
                        .data('href', m.href)
                        .html(m.text)
                        .click(function() {
                            toLocationPath($(this).data('href'));
                        })
                )
        );
        if (i == (list.length - 1)) {
            document.title = m.text;
        }
    });
}